package sources;
import java.awt.event.*;
import java.awt.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

import javax.swing.*;

/**
 * View Frame
 * 
 * A class allowing the user to view the current state of an ICalendar.
 *
 * @author Alana Meditz
 * @author Ty Yago
 * @author Katherine Kishaba
 * @author Jimmy CUmming
 * 
 */

public class ViewFrame extends JFrame {
	private static final int WIDTH = 500;
	private static final int HEIGHT = 400;
	
	private ICalendar iCal;
	
	private JTextArea viewTA;
	
	/**
	 * Constructor method.  Creates the frame to view the given ICalendar.
	 * @param iCal ICalendar to be viewed.
	 */
	public ViewFrame(ICalendar iCal) {
		this.iCal = iCal;
		
		setTitle("View");
		setSize(WIDTH, HEIGHT);
		setVisible(true);
				
		viewTA = new JTextArea("");
		viewTA.setEditable(false);

		buildTextArea();
				
		JScrollPane scrollPane = new JScrollPane(viewTA);
		add(scrollPane, BorderLayout.CENTER);
	}
	
	/**
	 * Instantiates the JTextArea of this frame with the information of the ICalendar.
	 */
	private void buildTextArea() {
		viewTA.append("BEGIN:VCALENDAR\n");
		for(ICalProperty property : iCal.getICalProperties()) {
			viewTA.append(property.getName() + ":" + property.getValue() + "\n");
		}
		for(ICalComponent iCalComponent : iCal.getICalComponents()) {
			viewTA.append("BEGIN:" + iCalComponent.getType() + "\n");
			for(ICalProperty property : iCalComponent.getComponentProperties()) {
				viewTA.append(property.getName() + ":" + property.getValue() + "\n");
			}
			viewTA.append("END:" + iCalComponent.getType() + "\n");
		}
		viewTA.append("END:VCALENDAR\n");
	}
}